package cn.tkb.user.controller;

import cn.tkb.basic.exception.BusinessException;
import cn.tkb.basic.util.AjaxResult;
import cn.tkb.user.service.IVerifycodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * 短信验证码发送接口
 */
@RestController
@RequestMapping("/verifycode")
public class VerifycodeController {
    @Autowired
    private IVerifycodeService verifycodeService;
    /**
     * 在前端传递参数很少的情况下可以使用map来接收对象
     * @param param
     * @return
     */
    @PostMapping("/SmsCode")
    public AjaxResult SmsCode(@RequestBody Map<String,String> param){
        String phone = param.get("phone");
        String type = param.get("type");
        try {
            verifycodeService.SmsCode(param);
            return AjaxResult.success();
        } catch (BusinessException e) {
            e.printStackTrace();
            return AjaxResult.fail(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.fail("系统繁忙，稍后重试！！！");
        }

    }
}
